package quartz;

import lombok.Getter;
import lombok.Setter;
import org.quartz.*;

import java.time.LocalDateTime;

/**
 * <h1>定时任务</h1>
 *
 * @author zhh 2019-05-31
 */
@Getter
@Setter
public class TimerJob implements Job {
    /**
     * Job实现类中添加setter方法对应JobDataMap的键值
     */
    private String message;
    private Float floatJobValue;
    private Double doubleTriggerValue;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("Current Exec Time is: " + LocalDateTime.now());
        JobKey jobKey = jobExecutionContext.getJobDetail().getKey();
        System.out.println("Quartz Job");
        System.out.println("my name and group is: " + jobKey.getName() + ", " + jobKey.getGroup());
        TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
        System.out.println("my trigger and group is: " + triggerKey.getName() + ", " + triggerKey.getGroup());
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        JobDataMap triggerDataMap = jobExecutionContext.getTrigger().getJobDataMap();
        JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
        String jobMsg = jobDataMap.getString("message");
        // 从Map直接获取JobDataMap
        // float floatJobValue = jobDataMap.getFloat("floatJobValue");
        // double doubleTriggerValue = triggerDataMap.getDouble("doubleTriggerValue");

        System.out.println("job message is: " + jobMsg);
        System.out.println("massage is " + mergedJobDataMap.getString("message"));
        System.out.println("massage is: " + message);
        System.out.println("float job value: " + floatJobValue);
        System.out.println("double trigger value is: " + doubleTriggerValue);
    }
}
